package old.resourceCache;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;


//import utilities.SimpleHashMap;

//Manages given .zip archive
public class ZipArchive implements IResourceFile {
	
	private ArrayList<ZipEntry> fileList;
	private String archiveName;
	private File archive;
	private ZipFile zipFile;
	private Enumeration entries;
	
	public ZipArchive(File archive)
	{
		this.archive = archive;
		archiveName = archive.getName();
		this.VOpen(); //is this smart to do in a constructor?
	}
	
	//creates a list of zipfile contents
	public boolean VOpen() 
	{
		if (archive.canRead())
		{
			try {				
				zipFile = new ZipFile(archive);						
				entries = zipFile.entries();
				
				while (entries.hasMoreElements())
				{
					fileList.add((ZipEntry) entries.nextElement());						
				}
			} catch (ZipException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			}
			return true;		
		}
		else 
			return false;		
	}
	
	public int getResource(ZipEntry entry, char[] buffer)//why char buffer
	{
		try {
			BufferedInputStream input = new BufferedInputStream(zipFile.getInputStream(entry));
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return 0;
	}
	
	//return size of ZipFile entry for buffer
	public long getResourceSize(ZipEntry entry)
	{
		return entry.getSize();
	}
	
	//retrieves list of zipfile contents
	public ArrayList<ZipEntry> getContents()
	{
		return fileList;
	}
	
	public String getArchiveName()
	{
		return archiveName;
	}
	

}
